package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.SetmealDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private SetmealDao setmealDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception{
        Map<String, Object> map = new HashMap<>();
        //获得本周一的日期
        String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获得本月一号的日期
        String month = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //报表时间
        String reportDate = DateUtils.parseDate2String(new Date());
        //本日新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(reportDate);
        //会员总数
        Integer totalMember = memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);
        //本月新增会员数thisMonthNewMember
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(month);
        //当天预约人数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(reportDate);
        //当天就诊人数todayVisitsNumber
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(reportDate);
        //本周预约人数thisWeekOrderNumber
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(monday);
        //本周就诊人数thisWeekVisitsNumber
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(monday);
        //本月预约人数thisMonthOrderNumber
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(month);
        //本月就诊人数thisMonthVisitsNumber
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(month);
        //hotSetmeal
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        map.put("reportDate",reportDate);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);

        return map;
    }

    @Override
    public Integer findmemberCount(String minDate, String s) {
      Map map = new HashMap<>();
      map.put("minDate",minDate);
      map.put("s",s);
        return memberDao.findmemberCount(map);

    }
}
